mui.init();
var brushing_data;
mui.plusReady(function () {
    //用户左滑  下一题
    document.addEventListener("swipeleft", function () {
        console.log('前往下一题');

        var m = brushing_data.q_index + 1;
        if (m == brushing_data.orther_data.count_num) {
            mui.toast('已经是最后一题咯!', {
                duration: 1000,
                type: 'div'
            });
        } else {
            brushing_data.q_index++; //翻到下一题
        }
    });

    //用户右滑  返回上一题
    document.addEventListener("swiperight", function () {
        console.log('返回上一题');
        if (brushing_data.q_index == 0) {
            mui.toast('该题目是第一题哦', {
                duration: 1000,
                type: 'div'
            });
        } else {
            brushing_data.q_index--; //翻到上一题
        }
    });

    var self = plus.webview.currentWebview();
    var catid = self.catid;
    var type = self.type;
    brushing_data = new Vue({
        el: '#jiexi_box',
        data: {
            orther_data: '',
            collection_status: 0,
            question_lists: '',
            q_index: 0,
            question_id: '',
            con: '',
            type: 1,
            yes_num: '',
            cailiaoCate: 'cailiao',
            cailiaoTab: 0,
        },
        mounted() {
            this.get_kdetails();
        },
        watch: {
            q_index: function (val, oldVal) {
                if (val == this.orther_data.count_num) {
                    mui.toast('是最后一题咯', {
                        duration: 1000,
                        type: 'div'
                    });
                    return false;
                }
                this.type = this.question_lists[val].type;
                this.question_id = this.question_lists[val].id;
                this.collection_status = this.question_lists[val].collection_status;
                if (this.type == 50) {
                    this.cailiaoTab = this.question_lists[val]['cl_li'][0].cailiao_index;
                    this.cailiaoCate = 'cailiao';
                }
            },
            myan: function () {
                var str = this.myan;
                var len = str.replace(/[\u0391-\uFFE5]/g, "aa").length;
                this.yes_num = 300 - len;
            },
        },
        methods: {
            get_kdetails: function () {
                showWatting();
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/questionbank/choice_question/get_user_history_detail',
                    data: {
                        'type': type,
                        'id': catid
                    },
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    dataType: 'json',
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            brushing_data.question_lists = msg.data.question;
                            brushing_data.orther_data = msg.data.other;
                            brushing_data.question_id = msg.data.question[0].id;
                            brushing_data.type = msg.data.question[0].type;
                            brushing_data.notes_list = msg.data.question[0].notes;
                            brushing_data.collection_status = msg.data.question[0].collection_status;
                        } else if (msg.code == 0) {
                            mui.toast(msg.msg, {duration: 1500,type: 'div'});
                            setTimeout(function () {
                                mui.back();
                            }, 1500)
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('加载失败!', {duration: '200',type: 'div'});
                        setTimeout(function () {
                            mui.back();
                        }, 1500)
                    },
                    complete:function () {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
            tijiao_notes: function () {
                $('.popMask').hide();
                $('.popNotes').animate({
                    'bottom': '-100%'
                }, 300).hide(300);
                var api_host = plus.storage.getItem('HOST_URL');
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: api_host + "/api/questionbank/public/add_question_notes",
                    data: {
                        'question_id': brushing_data.question_id,
                        'category': brushing_data.question_list[brushing_data.q_index]['category'],
                        'content': brushing_data.con
                    },
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    success: function (msg) {
                        mui.toast(msg.msg, {
                            duration: '3000',
                            type: 'div'
                        });
                    },
                    error: function () {
                        mui.toast('笔记添加失败!', {duration: '200',type: 'div'});
                    }
                });
            },
            add_collection: function () {
                questionCollection(this.question_id, this.type,brushing_data);
            },
            add_user_notes: function () {
                $('.popMask').show();
                $('.popNotes').animate({
                    'bottom': '0%'
                }, 300).show();
            },
            yc_notes: function () {
                //隐藏答题卡
                $('.popMask').hide();
                $('.popNotes ,.popNotes3').animate({
                    'bottom': '-100%'
                }, 300).hide(300);
            },
            open_jc: function () {
                //打开纠错界面
                mui.openWindow({
                    url: 'errorCorrection.html',
                    extras: {
                        'question_id': this.question_id,
                        'category': this.type
                    },
                    createNew: false,
                    show: {
                        autoShow: false
                    }
                })
            },
            select_cailiaoTab: function (e) {
                this.cailiaoCate = e.target.getAttribute('tabCat');
                if (e.target.getAttribute('tabCat') == 'wenti') {
                    this.cailiaoTab = e.target.getAttribute('qINdex');
                } else if (e.target.getAttribute('tabCat') == 'cailiao') {
                    this.cailiaoTab = e.target.getAttribute('cINdex');
                }
            },
            //修改笔记
            modify_user_notes: function () {
                $('.popMask').show();
                $('.popNotes3').animate({
                    'bottom': '0%'
                }, 300).show();
            },
            queren_notes: function () {
                $('.popMask').hide();
                $('.popNotes3').animate({
                    'bottom': '-100%'
                }, 300).hide(300);
            },
        }
    })
})